package com.adobe.training.core;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import javax.jcr.Repository;
import javax.servlet.ServletException;

import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;


    @SlingServlet(paths = "/bin/company/testFile", methods = "GET") 
    public class TestFileServlet extends SlingSafeMethodsServlet {


    @Reference
    private Repository repository;
    private static final long serialVersionUID =-3960692666512058118L;
    private static String tmpFile = "C:/Users/stai/Documents/temp/test.txt";
    
    @Override
    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
        response.setHeader("Content-Type", "application/json");
        File file = new File(tmpFile);
        BufferedReader reader = new BufferedReader(new FileReader(file)); 
        response.getWriter().print(reader.readLine());
        reader.close();
    }
}